<?php

namespace BWL\webshopBundle\Helper;


class PrimaryRequirements
{
  const MAX_NUMBERS = 3;

  private $average = array();
  private $average_next_index = 0;

  public function addForAvg($elem) {
    if(sizeof($this->average) < self::MAX_NUMBERS) {
      $this->average[] = $elem;
    } else {
      $this->average[$this->average_next_index] = $elem;
      $this->average_next_index = ($this->average_next_index + 1) % self::MAX_NUMBERS;
    }
  }

  public function getAvg() {
    $length = sizeof($this->average);
    if($length > 0) {
      return array_sum($this->average) / $length;
    }
    return 0;
  }

}
